package com.example.sw_zx_app.controller;

import com.example.sw_zx_app.model.RestResp;
import com.example.sw_zx_app.service.OpenApiZongxinAppService;
import com.example.sw_zx_app.service.OpenApiZongxinAppServiceImpl;
import com.example.sw_zx_app.util.AESCrypt;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.security.GeneralSecurityException;

@RestController
@RequestMapping("/solar-verse/open/api/v1")
public class OpenApiZongxinAppController {

    @Autowired
    OpenApiZongxinAppServiceImpl openApiZongxinAppService;

    @org.springframework.web.bind.annotation.PostMapping(value = "/android/main/appReceivePic")
    public Object appReceivePicSync( String inspectGuid,
                                               String deviceType,
                                               String groupGuid,
                                               String deviceGuid,
                                               String rfid,
                                               Integer sumPic,
                                               Integer picBatch,
                                               Integer picMold,
                                               String fileName,
                                               Integer isOver,
                                               String param,
                                              @org.springframework.web.bind.annotation.RequestPart("file") MultipartFile[] imgs) throws GeneralSecurityException {


        // 解密 inspectGuid工单id
        String decrypt = AESCrypt.decrypt("uav-aes-secret-key", param);
        // 创建ObjectMapper实例
        ObjectMapper mapper = new ObjectMapper();

        // 将JSON字符串解析为JsonNode对象
        JsonNode jsonNode = null;
        try {
            jsonNode = mapper.readTree(decrypt);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        // 提取inspectGuid字段
        String Guid = jsonNode.get("inspectGuid").asText();
        String isEnd = jsonNode.get("isOver").asText();
        openApiZongxinAppService.appReceivePicSync2(Guid,imgs,isEnd,jsonNode);
        // 返回解密后的数据
        return RestResp.success();
    }
        // 解密 inspectGuid工单id
}
